<template>
    <div v-if="Object.keys(goodsInfo).length !== 0" class="goods-info">
        <div class="info-desc clear-fix">
            <div class="start"></div>
            <div class="desc">{{ goodsInfo.desc }}</div>
            <div class="end"></div>
        </div>
        <div class="info-key">
            <div class="info-key-text">
            {{ goodsInfo.detailImage[0].key }}
            </div>
        </div>
        <div class="info-list">
            <img v-for="(item, i) in goodsInfo.detailImage[0].list" :key="i" :src="item" @load="imgLoad">
        </div>
    </div>
</template>

<script>
export default {
    name: 'DetailGoodsInfo',
    props: { 
       goodsInfo: {
           type: Object,
           default() {
               return {}
           }
       }
    },
    data() {
        return{
           coumter: 0,
           imagesLength: 0
        }
    },
    methods: {
        imgLoad() {
            // 判断所有图片都加载完成, 在进行一次回调
            // if(++this.coumter === this.imagesLength) {
            //     this.$emit('imageLoad')
            // }
           
            // 对应混入防抖函数
            this.$emit('imageLoad')
        }
    },
    watch:{
        goodsInfo() {
            this.imagesLength = this.goodsInfo.detailImage[0].list.length
        }
    }
}
</script>

<style scoped>
.goods-info .info-desc{
  padding: 50px 16px 8px 16px;
}

.goods-info .info-key{
  padding: 0 16px 40px 16px;
}

.goods-info .info-desc .desc,
.goods-info .info-key .info-key-text{
    background-color: #e4e4e47a;
    border-radius: 5px;
    padding: 8px 5px;
}
.goods-info .info-list{
    padding: 0 8px;
}
.goods-info .info-list img{
    width: 100%;
    height: 100%;
}
</style>>
